import {
    IAsset,
    IDrawType,
    ILabel,
    ILabelDataSet,
    ILabelTag,
} from '@/components/common/LabelEditor/types'
import { IGeoFile } from '@/types/geofile'
import { defineStore } from 'pinia'
import { computed, ref } from 'vue'

export const useLabelStore = defineStore('labelStore', () => {
    // 当前标签
    const curTag = ref<ILabelTag>()

    // 标签列表
    const tagList = ref<ILabelTag[]>([])

    // 当前的标注列表
    const labelList = ref<ILabel[]>([])

    // 当前工具栏激活的交互类型
    const drawType = ref<IDrawType>('Polygon')

    // 标注的数据源
    const assetList = ref<IAsset[]>([])
    // 当前标注的数据源
    const curAsset = ref<IAsset>()

    const curAssetIdx = computed(() => {
        if (curAsset.value) {
            const { path } = curAsset.value

            return assetList.value.findIndex((file) => file.path === path)
        } else {
            return -1
        }
    })

    const canPrevAsset = computed(() => {
        return curAssetIdx.value > 0
    })

    const curDataSet = ref<ILabelDataSet>()

    const cantNextAsset = computed(() => {
        return curAssetIdx.value < assetList.value.length - 1
    })

    const curLabelMode = ref<'map' | 'image'|'change-detection'>()


    return {
        curTag,
        tagList,
        labelList,
        drawType,
        assetList,
        curAsset,
        curAssetIdx,
        canPrevAsset,
        cantNextAsset,
        curDataSet,
        curLabelMode,
    }
})
